import { Controller, Get, Post, UploadedFiles, UseInterceptors, Body, } from '@nestjs/common';
import { BiliService } from '@/modules/bili/bili.service';
import { FileInterceptor, FileFieldsInterceptor } from '@nestjs/platform-express';
import { Express } from 'express';

@Controller("bili")
export class BiliController {
  constructor(private readonly biliService: BiliService) {
  }

  @Post("publish")
  @UseInterceptors(FileFieldsInterceptor([
    { name: 'cover', maxCount: 1 },
    { name: 'video', maxCount: 1 },
  ]))
  publish(@UploadedFiles() files: {cover: Express.Multer.File[], video: Express.Multer.File[]}, @Body() options: any) {
    const opt = {
      videoFile: files.video[0],
      coverFile: files.cover[0],
      config: options
    }
    return this.biliService.publish(opt)
  }

  @UseInterceptors(FileFieldsInterceptor([
    { name: 'avatar', maxCount: 1 },
    { name: 'background', maxCount: 1 },
  ]))
  uploadFile(@UploadedFiles() files: { avatar?: Express.Multer.File[], background?: Express.Multer.File[] }) {
    console.log(files);
  }

  @Get("/debug")
  debug() {
    return this.biliService.getTypeList()
  }
}